package com.github.wxiaoqi.security.biz.biz.pay;

import java.math.BigDecimal;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.wxiaoqi.security.biz.entity.CmsScenesOrder;
import com.github.wxiaoqi.security.biz.feign.CrmFeign;
import com.github.wxiaoqi.security.biz.mapper.CmsScenesOrderMapper;

/**
 * 支付回调处理
 * @author he
 *
 */
@Service
public class PayCallBackBiz {
	
	private static final Logger logger = (Logger) LoggerFactory.getLogger(PayCallBackBiz.class);

	@Autowired
	private CrmFeign crmFeign;
	@Autowired
	private CmsScenesOrderMapper cmsScenesOrderMapper;
	
	/**
	 * 支付完成回调
	 * @param request
	 * @return
	 */
	public void payCallBack(Map<String, Object> params){
		String platformId = (String) params.get("platformId");
		String orderNo = (String) params.get("orderNo");
		String txStatus = (String) params.get("txStatus");
		String amount = (String) params.get("amount");
		BigDecimal amountDecimal = new BigDecimal(amount);
		CmsScenesOrder cmsScenesOrder = new CmsScenesOrder();
		cmsScenesOrder.setPlatformId(platformId);
		cmsScenesOrder.setPayOrderNo(orderNo);
		CmsScenesOrder selectOrder = cmsScenesOrderMapper.selectOne(cmsScenesOrder);
		if(null == selectOrder){
			logger.info("支付完成回调-订单不存在.......{}",params);
			return;
		}
		if(0 != selectOrder.getTxAmt().compareTo(amountDecimal)){
			logger.info("支付完成回调-金额不一致.......{}",params);
			return;
		}
		
		//支付成功入账
		if("00".equals(txStatus)){
			crmFeign.inAccounting(params);
		}
		
		//更新场景订单
		String scenesCode = selectOrder.getScenesCode();
		if("".equals(scenesCode)){
			//竞拍
			
		}else if("".equals(scenesCode)){
			//拼团
			
		}else if("".equals(scenesCode)){
			//店内点餐
			
		}else if("".equals(scenesCode)){
			//预订点餐
			
		}else if("".equals(scenesCode)){
			//外卖
			
		}
	}
}
